package top.vains.server;

import lombok.Setter;

import java.io.Serializable;
import java.math.BigDecimal;

import static java.math.BigDecimal.ROUND_HALF_UP;
import static java.math.BigDecimal.valueOf;

/**
 * 内存相关信息
 * @author zzg
 *
 */
public class Mem implements Serializable {
	/**
     * 内存总量
     */
	@Setter
    private double total;
 
    /**
     * 已用内存
     */
	@Setter
    private double used;
 
    /**
     * 剩余内存
     */
	@Setter
    private double free;

	@Setter
	private double usage;
 
    public double getTotal() {
        BigDecimal b = valueOf(total / (1024 * 1024 * 1024));
        return b.setScale(2, ROUND_HALF_UP).doubleValue();
    }
 
    public double getUsed() {
        BigDecimal b = valueOf(used / (1024 * 1024 * 1024));
        return b.setScale(2, ROUND_HALF_UP).doubleValue();
    }
 
    public double getFree() {
        BigDecimal b = valueOf(free / (1024 * 1024 * 1024));
        return b.setScale(2, ROUND_HALF_UP).doubleValue();
    }
 
    public double getUsage() {
        BigDecimal b = valueOf((used / total) * 100);
        return b.setScale(2, ROUND_HALF_UP).doubleValue();
    }
}